package com.kxmall.web.controller.vehicle.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.kxmall.capacity.domain.vo.KxCapacityBoxVo;
import com.kxmall.capacity.domain.vo.KxCapacityVo;
import com.kxmall.common.constant.CacheConstants;
import com.kxmall.common.core.domain.entity.SysUser;
import com.kxmall.common.utils.BeanCopyUtils;
import com.kxmall.common.utils.HttpUtils;
import com.kxmall.common.utils.OrderUtil;
import com.kxmall.system.mapper.SysUserMapper;
import org.apache.commons.lang3.StringUtils;
import com.kxmall.common.utils.redis.RedisUtils;
import com.kxmall.vehicle.domain.*;
import com.kxmall.vehicle.domain.bo.KxVehicleBoxDownGoodsBo;
import com.kxmall.vehicle.domain.bo.KxVehicleBoxUpGoodsBo;
import com.kxmall.vehicle.domain.vo.KxVehicleBoxGoodsVo;
import com.kxmall.vehicle.domain.vo.KxVehicleBoxUpGoodsVo;
import com.kxmall.vehicle.domain.vo.KxVehicleInGoodsVo;
import com.kxmall.vehicle.domain.vo.KxVehicleVo;
import com.kxmall.vehicle.mapper.*;
import com.kxmall.web.controller.vehicle.service.IKxWebVehicleService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.Duration;
import java.util.*;

/**
 *
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class KxWebVehicleService implements IKxWebVehicleService {

    @Autowired
    private SysUserMapper sysUserMapper;
    @Autowired
    private KxVehicleMapper vehicleMapper;
    @Autowired
    private KxVehicleInGoodsMapper vehicleInGoodsMapper;
    @Autowired
    private KxVehicleBoxGoodsMapper vehicleBoxGoodsMapper;
    @Autowired
    private KxVehicleBoxUpGoodsMapper vehicleBoxUpGoodsMapper;
    @Autowired
    private KxVehicleBoxDownGoodsMapper vehicleBoxDownGoodsMapper;
    @Autowired
    private KxVehicleBoxGoodsOrderMapper vehicleBoxGoodsOrderMapper;

    @Value("${capacity.loginURL}")
    private String loginURL = "https://middle.office.xingshentech.com/api/sys/singleLogin?userName=qdqTest&password=qdqTest";

    @Value("${capacity.openURL}")
    private String openURL = "https://middle.office.xingshentech.com/api/task/interface/cabinetMissionOpen";

    @Value("${capacity.getURL}")
    private String getURL = "https://middle.office.xingshentech.com/api/task/interface/capacityResourceBoxStatusById?capacityResourceId=";

    public String getVehicleLoginToken(){
        String response = HttpUtils.get(loginURL);
        Map<String,Object> rpMap= JSON.parseObject(response, HashMap.class);
        if ("0".equals(""+rpMap.get("code"))){
            String data = ""+rpMap.get("data");
            Map<String,Object> rpMap1= JSON.parseObject(data, HashMap.class);
            String token = ""+rpMap1.get("token");
            Duration duration = Duration.ofDays(1);
            RedisUtils.setCacheObject(CacheConstants.CAPACITY_LOGIN_TOKEN_KEY, token, duration);
            return token;
        }
        return "";
    }

    @Override
    public KxVehicleVo getVehicleBoxGoodsInfo(String vehicleNo,String username) {
        log.info("getVehicleBoxGoodsInfo vehicleNo={}", vehicleNo);
        KxVehicleVo vehicleVo = vehicleMapper.selectVoOne(
                new LambdaQueryWrapper<KxVehicle>().eq(KxVehicle::getVehicleNo, vehicleNo));
        if (vehicleVo != null) {
            String token = RedisUtils.getCacheObject(CacheConstants.CAPACITY_LOGIN_TOKEN_KEY);
            if(StringUtils.isEmpty(token)){
                token = getVehicleLoginToken();
            }
            Map<String, String> headers = new HashMap<>();
            if(StringUtils.isNotEmpty(token)) {
                headers.put("token", token);
            }
            log.info("getVehicleBoxGoodsInfo vehicleNo={} token={}", vehicleNo, token);
            String response = HttpUtils.get(getURL+vehicleNo,null, headers);
            log.info("getVehicleBoxGoodsInfo vehicleNo={} response={}",vehicleNo, response);
            Map<String,Object> rpMap = JSON.parseObject(response, HashMap.class);
            if ("0".equals(""+rpMap.get("code"))){
                vehicleVo.setIsOnline(1);
                KxCapacityVo kxCapacityVo = JSON.parseObject(""+rpMap.get("data"), KxCapacityVo.class);
                List<KxCapacityBoxVo> kxCapacityBoxVOList = kxCapacityVo.getBoxStatusInfoVOList();
                if(CollectionUtils.isNotEmpty(kxCapacityBoxVOList)){
                    List<KxVehicleBoxGoods> vehicleBoxGoodsList = vehicleBoxGoodsMapper.selectList(
                            new LambdaQueryWrapper<KxVehicleBoxGoods>().eq(KxVehicleBoxGoods::getVehicleNo, vehicleNo)
                    );
                    List<KxVehicleBoxGoodsVo> vehicleBoxGoodsVos = new ArrayList<>();
                    if(CollectionUtils.isNotEmpty(vehicleBoxGoodsList)){
                        for(KxVehicleBoxGoods vehicleBoxGoods : vehicleBoxGoodsList){
                            KxVehicleBoxGoodsVo vehicleBoxGoodsVo = new KxVehicleBoxGoodsVo();
                            BeanCopyUtils.copy(vehicleBoxGoods, vehicleBoxGoodsVo);
                            if((vehicleBoxGoodsVo.getBoxStatus() == 0)
                                &&(vehicleBoxGoodsVo.getBoxStates() == 1)
                                &&(vehicleBoxGoodsVo.getUpGoodsId() != null)
                                &&(vehicleBoxGoodsVo.getUpGoodsId() != 0)) {
                                KxVehicleBoxUpGoodsVo vehicleBoxUpGoodsVo = vehicleBoxUpGoodsMapper.selectVoById(vehicleBoxGoodsVo.getUpGoodsId());
                                if(vehicleBoxGoodsVo != null) {
                                    vehicleBoxGoodsVo.setGoodsNumbers(vehicleBoxUpGoodsVo.getGoodsNumbers());
                                    vehicleBoxGoodsVo.setSalesStatus(vehicleBoxUpGoodsVo.getSalesStatus());
                                    vehicleBoxGoodsVo.setUpPerson(vehicleBoxUpGoodsVo.getUpPerson());
                                    vehicleBoxGoodsVo.setUpTime(vehicleBoxUpGoodsVo.getUpTime());
                                    vehicleBoxGoodsVo.setUpDay(vehicleBoxUpGoodsVo.getUpDay());
                                    vehicleBoxGoodsVo.setRemarks(vehicleBoxUpGoodsVo.getRemarks());
                                    vehicleBoxGoodsVo.setCount(vehicleBoxUpGoodsVo.getCount());
                                    vehicleBoxGoodsVo.setPrice(vehicleBoxUpGoodsVo.getPrice());
                                    vehicleBoxGoodsVo.setAmount(vehicleBoxUpGoodsVo.getAmount());
                                    KxVehicleInGoods vehicleInGoods = vehicleInGoodsMapper.selectById(vehicleBoxGoodsVo.getInGoodsId());
                                    if(vehicleInGoods != null) {
                                        vehicleBoxGoodsVo.setInVehicleOrder(vehicleInGoods.getInVehicleOrder());
                                        vehicleBoxGoodsVo.setInVehicleCount(vehicleInGoods.getInVehicleCount());
                                        vehicleBoxGoodsVo.setProductId(vehicleInGoods.getProductId());
                                        vehicleBoxGoodsVo.setProductName(vehicleInGoods.getProductName());
                                        vehicleBoxGoodsVo.setProductAttrId(vehicleInGoods.getProductAttrId());
                                        vehicleBoxGoodsVo.setProductAttrName(vehicleInGoods.getProductAttrName());
                                        vehicleBoxGoodsVo.setCategoryId(vehicleInGoods.getCategoryId());
                                        vehicleBoxGoodsVo.setCategoryName(vehicleInGoods.getCategoryName());
                                        vehicleBoxGoodsVo.setOrPrice(vehicleInGoods.getOrPrice());
                                        //vehicleBoxGoodsVo.setBarCode(vehicleInGoods.getBarCode());
                                        vehicleBoxGoodsVo.setStock(vehicleInGoods.getStock());
                                        vehicleBoxGoodsVo.setSalesStatus(vehicleInGoods.getSalesStatus());
                                    }
                                }
                            }
                            for(KxCapacityBoxVo capacityBoxVo : kxCapacityBoxVOList){
                                if((vehicleBoxGoodsVo.getBoxIndex().intValue() == capacityBoxVo.getBoxIndex().intValue())
                                        &&(vehicleBoxGoodsVo.getBoxStatus().intValue() != capacityBoxVo.getBoxStatus().intValue())){
                                    vehicleBoxGoodsVo.setBoxStatus(capacityBoxVo.getBoxStatus());
                                    vehicleBoxGoodsMapper.updateVehicleBoxStatus(vehicleBoxGoodsVo.getId(), capacityBoxVo.getBoxStatus());
                                }
                            }
                            vehicleBoxGoodsVos.add(vehicleBoxGoodsVo);
                        }
                    }
                    vehicleVo.setVehicleBoxGoodsVos(vehicleBoxGoodsVos);
                }
                //log.info("getVehicleBoxGoodsInfo vehicleVo={}", JSONObject.toJSONString(vehicleVo));
            }else {
                if(username.equalsIgnoreCase("test")) {
                    vehicleVo.setIsOnline(1);
                    vehicleVo = createVehicleBoxGoodsInfo(vehicleVo, username);
                }else{
                    if ("401".equals("" + rpMap.get("code"))) {
                        getVehicleLoginToken();
                        vehicleVo = getVehicleBoxGoodsInfo(vehicleNo, username);
                        //log.info("getVehicleBoxGoodsInfo vehicleVo={}", JSONObject.toJSONString(vehicleVo));
                    }
                }
            }
        }
        log.info("getVehicleBoxGoodsInfo vehicleVo={}", JSONObject.toJSONString(vehicleVo));
        return vehicleVo;
    }
    @Override
    public KxVehicleVo createVehicleBoxGoodsInfo(KxVehicleVo vehicleVo, String username) {
        vehicleVo.setIsOnline(1);
        vehicleVo.setBoxNum(24);
        List<KxVehicleBoxGoodsVo> vehicleBoxGoodsVos = new ArrayList<>();
        List<KxVehicleBoxGoods> vehicleBoxGoodsList = vehicleBoxGoodsMapper.selectList(
                new LambdaQueryWrapper<KxVehicleBoxGoods>().eq(KxVehicleBoxGoods::getVehicleNo, vehicleVo.getVehicleNo())
        );
        if(CollectionUtils.isNotEmpty(vehicleBoxGoodsList)){
            for(KxVehicleBoxGoods vehicleBoxGoods : vehicleBoxGoodsList){
                KxVehicleBoxGoodsVo vehicleBoxGoodsVo = new KxVehicleBoxGoodsVo();
                BeanCopyUtils.copy(vehicleBoxGoods, vehicleBoxGoodsVo);
                if((vehicleBoxGoodsVo.getBoxStatus() == 0)
                        &&(vehicleBoxGoodsVo.getBoxStates() == 1)
                        &&(vehicleBoxGoodsVo.getUpGoodsId() != null)
                        &&(vehicleBoxGoodsVo.getUpGoodsId() != 0)) {
                    KxVehicleBoxUpGoodsVo vehicleBoxUpGoodsVo = vehicleBoxUpGoodsMapper.selectVoById(vehicleBoxGoodsVo.getUpGoodsId());
                    if(vehicleBoxGoodsVo != null) {
                        vehicleBoxGoodsVo.setGoodsNumbers(vehicleBoxUpGoodsVo.getGoodsNumbers());
                        vehicleBoxGoodsVo.setSalesStatus(vehicleBoxUpGoodsVo.getSalesStatus());
                        vehicleBoxGoodsVo.setUpPerson(vehicleBoxUpGoodsVo.getUpPerson());
                        vehicleBoxGoodsVo.setUpTime(vehicleBoxUpGoodsVo.getUpTime());
                        vehicleBoxGoodsVo.setUpDay(vehicleBoxUpGoodsVo.getUpDay());
                        vehicleBoxGoodsVo.setRemarks(vehicleBoxUpGoodsVo.getRemarks());
                        vehicleBoxGoodsVo.setCount(vehicleBoxUpGoodsVo.getCount());
                        vehicleBoxGoodsVo.setPrice(vehicleBoxUpGoodsVo.getPrice());
                        vehicleBoxGoodsVo.setAmount(vehicleBoxUpGoodsVo.getAmount());
                        KxVehicleInGoods vehicleInGoods = vehicleInGoodsMapper.selectById(vehicleBoxGoodsVo.getInGoodsId());
                        if(vehicleInGoods != null) {
                            vehicleBoxGoodsVo.setInVehicleOrder(vehicleInGoods.getInVehicleOrder());
                            vehicleBoxGoodsVo.setInVehicleCount(vehicleInGoods.getInVehicleCount());
                            vehicleBoxGoodsVo.setProductId(vehicleInGoods.getProductId());
                            vehicleBoxGoodsVo.setProductName(vehicleInGoods.getProductName());
                            vehicleBoxGoodsVo.setProductAttrId(vehicleInGoods.getProductAttrId());
                            vehicleBoxGoodsVo.setProductAttrName(vehicleInGoods.getProductAttrName());
                            vehicleBoxGoodsVo.setCategoryId(vehicleInGoods.getCategoryId());
                            vehicleBoxGoodsVo.setCategoryName(vehicleInGoods.getCategoryName());
                            vehicleBoxGoodsVo.setOrPrice(vehicleInGoods.getOrPrice());
                            //vehicleBoxGoodsVo.setBarCode(vehicleInGoods.getBarCode());
                            vehicleBoxGoodsVo.setStock(vehicleInGoods.getStock());
                            vehicleBoxGoodsVo.setSalesStatus(vehicleInGoods.getSalesStatus());
                        }
                    }
                }
                for(int boxIndex=1; boxIndex<25; boxIndex++){
                    if(vehicleBoxGoodsVo.getBoxIndex() == boxIndex){
                        vehicleBoxGoodsVo.setBoxStates(1);
                        vehicleBoxGoodsMapper.updateVehicleBoxStates(vehicleBoxGoodsVo.getId(), 1);
                    }
                }
                vehicleBoxGoodsVos.add(vehicleBoxGoodsVo);
            }
            vehicleVo.setVehicleBoxGoodsVos(vehicleBoxGoodsVos);
        }
        return vehicleVo;
    }

    @Override
    public Boolean openVehicleBox(Long userId, String vehicleNo, Integer boxIndex) {
        log.info("openVehicleBox userId={} vehicleNo={} boxIndex={}", userId, vehicleNo, boxIndex);
        Map<String, String> params = new HashMap<>();
        params.put("capacityResourceId", vehicleNo);
        params.put("boxIndex", boxIndex+"");

        String token = RedisUtils.getCacheObject(CacheConstants.CAPACITY_LOGIN_TOKEN_KEY);
        if(StringUtils.isEmpty(token)){
            token = getVehicleLoginToken();
        }
        Map<String, String> headers = new HashMap<>();
        if(StringUtils.isNotEmpty(token)) {
            headers.put("token", token);
        }
        log.info("openVehicleBox userId={} vehicleNo={} boxIndex={} token={}", userId, vehicleNo, boxIndex, token);
        String response = HttpUtils.post(openURL, params, headers);
        log.info(response);
        Map<String,Object> rpMap= JSON.parseObject(response, HashMap.class);
        if ("0".equals(""+rpMap.get("code"))){
            Boolean status = (Boolean) rpMap.get("status");
            return status;
        }else{
            SysUser sysUser = sysUserMapper.selectUserById(userId);
            if(sysUser.getUserName().equalsIgnoreCase("test")) {
                return true;
            }
        }
        return false;
    }

    @Override
    public List<KxVehicleInGoodsVo> getVehicleInGoods(String vehicleNo) {
        List<KxVehicleInGoodsVo> vehicleInGoodsVos = vehicleInGoodsMapper.selectVoList(
                new LambdaQueryWrapper<KxVehicleInGoods>()
                        .eq(KxVehicleInGoods::getVehicleNo, vehicleNo)
                        .eq(KxVehicleInGoods::getSalesStatus, 1)
                        .gt(KxVehicleInGoods::getStock, 0));
        if(vehicleInGoodsVos != null) {
            return vehicleInGoodsVos;
        }
        return new ArrayList<>();
    }

    @Override
    public Boolean vehicleBoxUpGoods(Long userId, String username, KxVehicleBoxUpGoodsBo bo) {
        KxVehicle vehicle = vehicleMapper.selectOne(
                new LambdaQueryWrapper<KxVehicle>()
                        .eq(KxVehicle::getVehicleNo, bo.getVehicleNo()));
        if (vehicle != null) {
            KxVehicleInGoods vehicleInGoods = vehicleInGoodsMapper.selectOne(
                    new LambdaQueryWrapper<KxVehicleInGoods>()
                    .eq(KxVehicleInGoods::getId, bo.getInGoodsId())
                    .eq(KxVehicleInGoods::getSalesStatus, 1)
                    .ge(KxVehicleInGoods::getStock, 1));
            if(vehicleInGoods != null) {
                int count = 1;
                BigDecimal price = vehicleInGoods.getOrPrice();
                BigDecimal amount = vehicleInGoods.getOrPrice();
                if((bo.getCount() != null)&&(bo.getCount() >= 1)
                        &&(vehicleInGoods.getStock()>=bo.getCount())){
                    count = bo.getCount();
                }
                if((bo.getPrice() != null)&&(!bo.getPrice().equals(vehicleInGoods.getOrPrice()))){
                    price = bo.getPrice();
                }
                if((bo.getAmount() != null)&&(!bo.getAmount().equals(bo.getPrice().multiply(new BigDecimal(count))))){
                    amount = bo.getAmount();
                }
                KxVehicleBoxUpGoods vehicleBoxUpGoods = new KxVehicleBoxUpGoods();
                vehicleBoxUpGoods.setVehicleId(vehicle.getId());
                vehicleBoxUpGoods.setVehicleNo(vehicle.getVehicleNo());
                vehicleBoxUpGoods.setVehicleName(vehicle.getVehicleName());
                vehicleBoxUpGoods.setBoxIndex(bo.getBoxIndex());
                vehicleBoxUpGoods.setCount(count);
                vehicleBoxUpGoods.setPrice(price);
                vehicleBoxUpGoods.setAmount(amount);
                vehicleBoxUpGoods.setGoodsNumbers(OrderUtil.orderSn());
                vehicleBoxUpGoods.setSalesStatus(1);
                vehicleBoxUpGoods.setInGoodsId(bo.getInGoodsId());
                vehicleBoxUpGoods.setUpPerson(username);
                vehicleBoxUpGoods.setRemarks("上架");
                vehicleBoxUpGoods.setCreateBy(username);
                vehicleBoxUpGoods.setCreateTime(new Date());
                int result = vehicleBoxUpGoodsMapper.insert(vehicleBoxUpGoods);
                if(result > 0){
                    vehicleInGoods.setStock(vehicleInGoods.getStock() - count);
                    if(vehicleInGoods.getStock() == 0){
                        vehicleInGoods.setSalesStatus(0);
                    }
                    result = vehicleInGoodsMapper.updateById(vehicleInGoods);
                    if(result > 0) {
                        log.info("vehicleInGoodsMapper.updateById() success!!! vehicleInGoods:{}",vehicleInGoods.toString());
                    }
                    KxVehicleBoxUpGoods kxVehicleBoxUpGoods = vehicleBoxUpGoodsMapper.selectByGoodsNumbers(vehicleBoxUpGoods.getGoodsNumbers());
                    if(kxVehicleBoxUpGoods != null) {
                        KxVehicleBoxGoods vehicleBoxGoods = vehicleBoxGoodsMapper.selectOne(
                                new LambdaQueryWrapper<KxVehicleBoxGoods>()
                                        .eq(KxVehicleBoxGoods::getVehicleId, vehicle.getId())
                                        .eq(KxVehicleBoxGoods::getVehicleNo, bo.getVehicleNo())
                                        .ge(KxVehicleBoxGoods::getBoxIndex, bo.getBoxIndex()));
                        if(vehicleBoxGoods != null) {
                            vehicleBoxGoods.setUpGoodsId(kxVehicleBoxUpGoods.getId());
                            vehicleBoxGoods.setInGoodsId(kxVehicleBoxUpGoods.getInGoodsId());
                            vehicleBoxGoods.setBoxStates(1);
                            Boolean ret = openVehicleBox(userId, bo.getVehicleNo(), bo.getBoxIndex());
                            if (ret) {
                                vehicleBoxGoods.setBoxStatus(1);
                            } else {
                                vehicleBoxGoods.setBoxStatus(0);
                            }
                            result = vehicleBoxGoodsMapper.updateById(vehicleBoxGoods);
                            if (result > 0) {
                                log.info("vehicleBoxGoodsMapper.updateById() success!!! vehicleBoxGoods:{}", vehicleBoxGoods.toString());
                            }
                        }
                    }
                    return true;
                }
            }
        }
        return false;
    }

    @Override
    public Boolean vehicleBoxDownGoods(Long userId, String username, KxVehicleBoxDownGoodsBo bo) {
        KxVehicleBoxGoods vehicleBoxGoods = vehicleBoxGoodsMapper.selectOne(
                new LambdaQueryWrapper<KxVehicleBoxGoods>()
                        .eq(KxVehicleBoxGoods::getVehicleNo, bo.getVehicleNo())
                        .eq(KxVehicleBoxGoods::getBoxIndex, bo.getBoxIndex()));
        if((vehicleBoxGoods.getUpGoodsId() != null)
                &&(vehicleBoxGoods.getUpGoodsId() > 0)
                &&(vehicleBoxGoods.getBoxStates() > 0)) {
            KxVehicleBoxUpGoods vehicleBoxUpGoods = vehicleBoxUpGoodsMapper.selectById(vehicleBoxGoods.getUpGoodsId());
            vehicleBoxUpGoods.setSalesStatus(0);
            vehicleBoxUpGoods.setRemarks("下架");
            int result = vehicleBoxUpGoodsMapper.updateById(vehicleBoxUpGoods);
            if(result > 0) {
                log.info("vehicleBoxUpGoodsMapper.updateById() success!!! vehicleBoxUpGoods:{}",vehicleBoxUpGoods.toString());
            }
            KxVehicleInGoods vehicleInGoods = vehicleInGoodsMapper.selectById(vehicleBoxUpGoods.getInGoodsId());
            if (vehicleInGoods != null) {
                vehicleInGoods.setStock(vehicleInGoods.getStock() + vehicleBoxUpGoods.getCount());
                result = vehicleInGoodsMapper.updateById(vehicleInGoods);
                if(result > 0) {
                    log.info("vehicleInGoodsMapper.updateById() success!!! vehicleInGoods:{}",vehicleInGoods.toString());
                }
            }
            vehicleBoxGoods.setInGoodsId(0L);
            vehicleBoxGoods.setUpGoodsId(0L);
            vehicleBoxGoods.setBoxStates(0);
            Boolean ret = openVehicleBox(userId, bo.getVehicleNo(), bo.getBoxIndex());
            if(ret){
                vehicleBoxGoods.setBoxStatus(1);
            }else {
                vehicleBoxGoods.setBoxStatus(0);
            }
            result = vehicleBoxGoodsMapper.updateById(vehicleBoxGoods);
            if(result > 0) {
                log.info("vehicleBoxGoodsMapper.updateById() success!!! vehicleBoxGoods:{}",vehicleBoxGoods.toString());
                KxVehicleBoxDownGoods vehicleBoxDownGoods = new KxVehicleBoxDownGoods();
                vehicleBoxDownGoods.setVehicleId(vehicleBoxUpGoods.getVehicleId());
                vehicleBoxDownGoods.setVehicleNo(vehicleBoxUpGoods.getVehicleNo());
                vehicleBoxDownGoods.setVehicleName(vehicleBoxGoods.getVehicleName());
                vehicleBoxDownGoods.setBoxIndex(vehicleBoxUpGoods.getBoxIndex());
                vehicleBoxDownGoods.setUpGoodsId(vehicleBoxUpGoods.getId());
                vehicleBoxDownGoods.setRemarks("下架");
                vehicleBoxDownGoods.setDownPerson(username);
                vehicleBoxDownGoods.setDownDay(new Date());
                vehicleBoxDownGoods.setDownTime(new Date());
                result = vehicleBoxDownGoodsMapper.insert(vehicleBoxDownGoods);
                if(result > 0) {
                    log.info("vehicleBoxDownGoodsMapper.insert() success!!! vehicleBoxDownGoods:{}", vehicleBoxDownGoods.toString());
                }
            }
            return true;
        }
        return false;
    }


}
